package Model.SQL;

import java.sql.*;
import Model.Config.AppConstants;

public class Connector {
    private static Connection conn;
    
    private Connector() {}
    
    private static void createConnector() 
    {
        try 
        {       
            Class.forName(AppConstants.driverClass).newInstance();
        } 
        catch(Exception e) 
        {
            System.out.println("Error: "  + e.getMessage());	
        }    
        connect();
    }
    
    private static void connect()
    {
        try 
        {
            conn = DriverManager.getConnection(AppConstants.url, AppConstants.user, AppConstants.pass);
        } 
        catch(SQLException e) 
        {
            System.out.println("SQLException: " + e.getMessage());
            System.out.println("SQLState: " + e.getSQLState());
            System.out.println("VendorError: " + e.getErrorCode());	
        }		
    }
    
    public static Connection getConnector()
    {
        if(conn == null)
            createConnector();
        return conn;
    }
}
